define(['jtopo','Json2xml'],function (jtopo,Json2xml){

	var customNephogram = function (jsonObj){
		this.initialize = function (){
			jsonObj._name && customNephogram.prototype.initialize.apply(this, arguments);
			this.myTopoStyle = true;
			var d = "node,goTopo".split(",");
			this.serializedProperties = this.serializedProperties.concat(d);
		}
		this.initialize();
		this.deserialize(jsonObj);
	}
	customNephogram.prototype = new JTopo.Node();

	customNephogram.prototype.serialize = function (){
		var _self = this;
		var node = new Array();
		for(var i=0;i<_self._nodes.length;i++){
			node[i] = {_refId:_self._nodes[i].id};
		}
		var jsonObj = {
			nephogram : {
				_id : _self.id,
				_name : _self.name,
				_x : _self.x,
				_y : _self.y,
				_width : _self.width,
				_height : _self.height,
				_desc : _self.desc,
				_cloudcolor : _self.cloudcolor,
				_goTopo : _self.goTopo,
				node : node
			}
		};
		if(jsonObj.nephogram._cloudcolor == undefined || 
				jsonObj.nephogram._cloudcolor == 'undefined'){
			jsonObj.nephogram._cloudcolor = "white";
		}
		var json2xml2 = new Json2xml();
		var resultXml_str = json2xml2.json2xml_str(jsonObj);
		return resultXml_str;
	}
	customNephogram.prototype.deserialize = function (jsonObj){
		this.x = Number(jsonObj._x);
		this.y = Number(jsonObj._y);
		this.width = jsonObj._width?Number(jsonObj._width):40;
		this.height = jsonObj._height?Number(jsonObj._height):40;
		this.id = Number(jsonObj._id);
		this.name = jsonObj._name;
		this.text = jsonObj._name;
		this.fontColor = '0,0,0';
		this.desc = jsonObj._desc;
		this.cloudcolor = jsonObj._cloudcolor;
		this.goTopo = jsonObj._goTopo;
		this.node = jsonObj.node;
	}

	return customNephogram;
	
});
